<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>CSC560 Design and Analysis of Real-Time Systems</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="../default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
	<div id="header">
		<h1>CSC560</h1>
		<h2>Design and Analysis of Real-Time Systems</h2>
		<ul>
			<li class="first">
				<a href="../index.html" accesskey="1" title="">Home</a>
			</li>
			<li>
				<a href="../project1/index.html" accesskey="2" title="">Project 1</a>
			</li>
			<li>
				<a href="index.html" accesskey="3" title=""><b>Project 2</b></a>
			</li>
			<li>
				<a href="../project3/index.html" accesskey="4" title="">Project 3</a>
			</li>
			<li>
				<a href="../project4/index.html" accesskey="4" title="">Project 4</a>
			</li>
			<li>
				<a href="../project5/index.html" accesskey="4" title="">Project 5</a>
			</li>
		</ul>
	</div>
</div>
<div id="content">
	<div id="colOne">
		<h2>Periodic Scheduling</h2>
		<h3>Run all tasks as PERIODIC tasks</h3>
		<p>
			In order to use PERIODIC scheduling policy, a Gantt chart must be established. Also, each periodic 
			task must complete before its assigned time slice expires or else it's an violation of RTOS scheduling 
			policy. Thus, one must first measure or estimate the maximum time it takes to complete each task and 
			so a Gantt chart can be created subsequently. With periodic scheduling, the Gantt chart becomes the 
			linear representation of task execution. For example, to use RTOS, the application must supply a 
			PPP[] array as the Gantt chart. 
			<br><br>
			For example, PPP[] = { A, 2, B, 3, A, 5, C, 1 } means executing A for 2 ticks, then B
			 for 3 ticks, then A again for 5 ticks, then C for 1 tick, then A again, and so on. The total cycle 
			 time is 2+3+5+1=11 ticks. That is, within 11 ticks, A executes twice, B once and C once.
			<br><br>			
			These periodic tasks are to be created in main() and then the system simply executes these tasks repeatedly 
			according to Gantt chart. Note that it is an RTOS runtime error if a periodic task does not complete within its 
			assigned time slot. This is why one must never underestimate the execution time of a task.	
		</p>
		<p>
			To gain more knowledge in how RTOS handled periodic tasks we first created a dummy test case 
			consisting of nothing but periodic tasks. In doing so, we learned that the code block of a 
			periodic task needed to reside in an infinite loop so it would not terminate on its own. 
			In addition, it had to yield by invoking Task_Next() before its assigned time slice 
			expired. 
			<br><br>						
			We learned that periodic scheduling might not be the most suitable for polling joystick because 
			all tasks took turn to execute in accordance with the assigned order and time slots. Thus, while 
			a joystick position was set (pulling low) the Joystick task might not be the running task. As a 
			result, joystick was not very responsive. In fact, we found that the responsiveness of joystick 
			was largely affected by the frequency of polling. High polling frequency resulted in too many 
			joystick commands sent out, while low polling frequency caused irresponsive joystick. In the end, 
			the time measurement performed in Part I and the experience from doing Project 1 guided us to the 
			optimal joystick polling frequency.
		</p>
		<p>
			Joystick task had very small execution time, 16 - 17 microseconds as shown in the data presented above. 
			Since RTOS used 5 milliseconds as the base unit for each tick, we assigned 1 tick = 5 milliseconds to this task.
			<br>
			<br>
			UART task took about 14 milliseconds, and so we tested it with 1,2,3 and 4 ticks. It turned out 1 or 2 ticks 
			would cause the OS to abort as the task wouldn't meet its deadline. 3 ticks could barely work for this task. 
			However, to err on the safe side, we decided to use 4 ticks = 20 milliseconds.
		</p>
		
		<p>
			The following diagram shows the periodic tasks alternating their execution. First, the joystick task is
			given 1 tick (5ms), then the radio tx task is given 2 ticks (10ms), followed by 5 ticks (25ms) for the radio rx task 
			and 4 ticks (20ms) for the uart task. The grey region represents the time the processor is idle. Note that the figure is not to scale. <br><br>
			<a href="../images/periodic_chart.jpg"><img src="../images/periodic_chart.jpg" alt="Periodic Chart" width="100%" /></a>
		</p>
	</div>
	
	<div id="colTwo">
		<h3>Project Sections</h3>
		<ul>
			<li class="first"><a href="part1.html">Time Measurements</a></li>
			<li>	<a href="part2.html">Scheduling Tasks with RTOS</a></li>
			<li>-	<a href="part2sub1.html">Periodic</a></li>
			<li>-	<a href="part2sub2.html">System and Round Robin</a></li>
			<li>-	<a href="part2sub3.html">Event Coordinated</a></li>
						<li>	<a href="doxygen/html/index.html">Doxygen</a></li>
						<li><a href="http://code.google.com/p/wireless-roomba">Google Code</a></li>

		</ul>
	</div>
</div>
<div id="footer">
	<p>@ 2009. All Rights Reserved. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
</div>
</body>
</html>
